import {
    createRouter,
    createWebHistory
} from 'vue-router'
import UserRouter from "./user"

const routes = [{
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue'),
    meta: {transition: 'slide-left'}
}, {
    path: '/',
    name: 'index',
    component: () => import('../views/index.vue'),
    meta: {transition: 'slide-left'}
}, UserRouter];

const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    if (to.name != 'login' && (!localStorage.getItem('token'))) {
        next({name: 'login'})
    } else {
        next()
    }
})

export default router